package dao;

import data.Scorse;
import data.Teacher;
import service.DbConnect;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class ScorseDao {
    private static DbConnect<Scorse> c=new DbConnect();
    private static Scorse scorse=new Scorse();
    public static List listAll(){
        try {
            return c.selectList("select * from scorse",scorse);
        }
        catch (Exception e){
            System.out.println("错误"+e.getMessage());
            return null;
        }
    }

    public static Scorse one(int id){
        try{
            return c.selectOne("select * from scorse where id="+id,scorse);
        }catch (Exception e){
            System.out.println("错误"+e.getMessage());
            return null;
        }
    }

    public static boolean add(Teacher t) throws Exception {
        String sql="insert into scorse (name,user,pwd) values"+t.simplSql();
        return c.execute(sql);
    }

    public static boolean del(int id) throws Exception{
        String sql="delete table scorse where id="+id;
        return c.execute(sql);
    }
    public static boolean edit(String type,String val,int id){
        try {
            String sql="update scorse set ?=? where id=?";
            PreparedStatement preparedStatement = c.preparedStatement(sql);
            preparedStatement.setString(1,type);
            preparedStatement.setString(2,val);
            preparedStatement.setInt(3,id);
            c.que(preparedStatement);
            return true;
        } catch (SQLException e) {
            System.out.println("错误："+e.getMessage());
            return false;
        }
    }
}
